<?php
/**
 * @auther zlq
 * @create_time 2020/5/21 11:49
 * @description
 */


namespace app\admin\controller;


use app\admin\service\User as UserService;
use think\Controller;

class Index extends Controller
{

    public function login()
    {
        $username = input('username');
        $password = input('password');
        $this -> assign('userName',$username);
        $this -> assign('userPwd',$password);
        return $this->fetch('login');
    }

    /**
     * @auther zlq
     * @create_time 2020/5/21 16:17
     * @description 用户登录处理
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function checkLogin()
    {
        $username = input('username');
        $password = input('password');
        $username = trim($username);
        $password = trim($password);
        if (!$username || !$password) {
            return json(['code' => -1, 'msg' => '参数不正确', 'data' => []]);
        }
        $UserService = new UserService();
        $res = $UserService->confirmUserLogin($username, $password);
        switch ($res) {
            case 1:
                return json(['status' => 1, 'msg' => '登录成功', 'data' => []]);
                break;
            case -1:
                return json(['status' => -1, 'msg' => '用户登录名不正确,请重试', 'data' => []]);
                break;
            case -2:
                return json(['status' => -2, 'msg' => '用户登录密码不正确,请重试', 'data' => []]);
                break;
            case -3:
                return json(['status' => -3, 'msg' => '用户信息不正确,请重试', 'data' => []]);
                break;
            case -4:
                return json(['status' => -4, 'msg' => '用户状态不正确,请重试', 'data' => []]);
                break;
            case -5:
                return json(['status' => -5, 'msg' => '用户登录密码不正确,请重试', 'data' => []]);
                break;
            default:
                return json(['status' => -1, 'msg' => '登录失败请重试', 'data' => []]);
                break;
        }
    }
}